<%@page import="org.feluma.sgci.util.Testes"%>
<%@page import="org.feluma.sgci.dao.CursoDAO"%>
<%@page import="org.feluma.sgci.entidade.Curso"%>
<%@page import="org.feluma.sgci.dao.UsuarioDAO"%>
<%@page import="org.feluma.sgci.entidade.Usuario"%>
<%@page language="java" contentType="text/html" pageEncoding="ISO-8859-1" %>
<%@page import="org.feluma.sgci.entidade.Perfil" %>
<%@page import="java.util.*" %>
<%@include file="include/usuarioLogado.jsp" %>
<%
Curso objCurso;
CursoDAO dao = new CursoDAO();
@SuppressWarnings("unchecked")
ArrayList<Curso> listaCurso = (ArrayList)request.getAttribute("listaCurso");
int tam = listaCurso.size();


String pNome = request.getParameter("nome");
String pProcesso = request.getParameter("processo");
String pag = request.getParameter("pag");
String quantidade = request.getParameter("lim");
if(quantidade == null) quantidade = "10";
int lim = Integer.parseInt(quantidade);
int lin = 0,fim,ini,lipag;

if(pag == null) pag = "1";
fim = Integer.parseInt(pag) * lim;
ini = fim - lim;
lipag = ini + lim;

String acao = request.getParameter("acao");
if(!acao.equals("pesquisar")) acao = "listar";
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>SGCI FCMMG :: Curso</title>
        <style type="text/css">
        <!--
        @import url("css/estilo.css");
        body {
            margin-left: 0px;
            margin-top: 0px;
            margin-right: 0px;
            margin-bottom: 0px;
        }
        -->
        </style>
        <script src="js/utilitarios.js"></script>
    </head>
<body background="imagens/fundo.gif" style="background-attachment:fixed">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="7"><jsp:include page="include/topo.jsp" flush="true" /></td>
  </tr>
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="60"><table width="95%" border="0" align="center" cellpadding="1" cellspacing="1">
            <tr>
              <td width="76%" class="titulo"><b>Curso</b></td>
              <td width="24%" class="texto"><div align="right">Usu&aacute;rio logado:
                <%=usuarioLogado.getNome()%>
              </div></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="95%" border="0" align="center" cellpadding="1" cellspacing="1">
            <tr>
              <td colspan="2"><form name="form1" method="post" action="Service">
              <fieldset style="border-color:#003366">
                  <legend class="texto"><strong> <img src="imagens/search.png" width="16" height="16"> Pesquisar Curso por </strong></legend>
                  <table width="100%" border="0" cellspacing="1" cellpadding="1">
                    <tr>
                      <td class="texto_pesquisa">&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td width="14%" class="texto"><div align="right">Nome do curso:</div></td>
                      <td width="86%"><input type="text" name="nome" id="nome" class="textBox" value="<%=Testes.isNull(pNome,"") %>"></td>
                    </tr>
                    <tr>
                      <td class="texto"><div align="right">Nome do processo:</div></td>
                      <td ><input type="text" name="processo" id="processo" class="textBox" value="<%=Testes.isNull(pProcesso,"") %>" >
                          <input type="submit" name="button" id="button" value="Buscar" class="botao"></td>
                    </tr>
                    <tr>
                      <td class="texto_pesquisa">&nbsp;</td>
                      <td><input name="classe" type="hidden" id="classe" value="org.feluma.sgci.controle.CursoControle" />
                        <input name="acao" type="hidden" id="acao" value="pesquisar" /></td>
                    </tr>
                  </table>
                  </fieldset>
              </form></td>
            </tr>
            <tr>
              <td width="94%"><span class="texto">
                <%out.print("Mostrando <b>"+(ini+1)+"</b> a <b>");
                if(tam < fim) out.print(tam); else out.print(fim);
                out.print("</b> de <b>"+tam+"</b> Cursos cadastrados no sistema");%>
                </span></td>
              <td width="6%">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" height="8">
                  <tr>
                    <td height="2" valign="top" bgcolor="#cccccc" style="border: 1 solid #333333">
                    	<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
                        <tr>
                          <th width="30%" height="30" align="center" background="imagens/barra.gif" class="texto"><strong>Processo</strong></th>
                          <th width="38%" height="30" align="center" background="imagens/barra.gif" class="texto"><strong>Curso</strong></th>
                          <th width="14%" height="30" align="center" background="imagens/barra.gif" class="texto"><strong>Status</strong></th>
                          <th width="9%"  height="30" align="center" background="imagens/barra.gif" class="texto"><strong>Nro Insc.</strong></th>
                          <th width="9%"  height="30" align="center" background="imagens/barra.gif" class="texto"><strong>Candidatos</strong></th>
                          
                        </tr>
                        <%
                         for(int i = 0; i < listaCurso.size(); i++){
                             if(i >= ini && i < fim){
                                 objCurso = (Curso)listaCurso.get( i );
                        %>
                        <tr id="tr<%=lin%>"  bgcolor="#f4f4f4" OnMouseOver="muda(tr<%=lin%>)" OnMouseOut="volta(tr<%=lin%>)">
                          <td class="texto"><%=dao.getProcesso(objCurso) %></td>
                          <td height="23" class="texto"><%=objCurso.getNome()%></td>
                          <td height="23" align="center" class="texto"><%=dao.statusCurso(objCurso) %></td>
                          <td height="23" align="center" class="texto"><%=dao.qtdeCandidatosCurso(objCurso)%></td>
                          <td height="23" align="center" class="texto"><a href="Service?classe=org.feluma.sgci.controle.CadastroControle&acao=listarCandidato&codEscola=<%=objCurso.getCodigoEscola()%>&codCurso=<%=objCurso.getCodigoCurso()%>"><img src="imagens/user.png" alt="Usuarios" width="16" height="16" border="0"></a></td>
                        </tr>
                        <%	}
                            lin++;
                        }
                        %>
                    </table></td>
                  </tr>
              </table></td>
            </tr>
          </table>
            <table width="329" align="center">
              <tr>
                <td width="321" valign="bottom"><form name="form2" method="post" action="Service">
                    <table width="100%" border="0" cellspacing="1" cellpadding="1">
                      <tr>
                        <td width="56%" valign="middle"><div align="center" class="texto">
                            <% if(Integer.parseInt(pag) != 1){ %>
                            <b><a href="Service?classe=org.feluma.sgci.controle.CursoControle&acao=<%=acao%>&pag=<%out.print(Integer.parseInt(pag)-1);%>&nome=<%=Testes.isNull(pNome,"")%>&processo=<%=Testes.isNull(pProcesso,"")%>&lim=<%=lim%>" class="link" title="Anterior"><font face="Small Fonts">&lt;&lt;</font></a></b>
                            <% }
                              double val1,val2;
                              val1 = (double) tam;
                              val2 = (double) lim;
                              double t_lim = Math.ceil(val1 / val2);
                              int limite = (int) t_lim;
                              out.print("p&aacute;gina "+pag+" de "+limite);
                              if(Integer.parseInt(pag) != t_lim && tam > 0){ %>
                            <b> <a href="Service?classe=org.feluma.sgci.controle.CursoControle&acao=<%=acao%>&pag=<%out.print(Integer.parseInt(pag)+1);%>&nome=<%=Testes.isNull(pNome,"")%>&processo=<%=Testes.isNull(pProcesso,"")%>&lim=<%=lim%>" class="link" title="Pr&oacute;xima"><font face="Small Fonts">&gt;&gt;</font></a></b>
                            <%}%>
                        </div></td>
                        <td width="44%"><select name="pag" class="listBox" id="pag">
                            <%for(int n=1; n<=limite; n++){%>
                            <option value="<%=n%>" <%if(n == Integer.parseInt(pag)) out.print("selected"); %>><%=n%></option>
                            <%}%>
                          </select>
                            <input type="submit" name="button3" id="button3" value="Ir" class="botao">
                            <input name="classe" type="hidden" id="classe" value="org.feluma.sgci.controle.CursoControle" />
                            <input name="acao" type="hidden" id="acao" value="<%=acao%>" />
                            <input name="nome" type="hidden" id="nome" value="<%=Testes.isNull(pNome,"")%>">
                            <input name="processo" type="hidden" id="processo" value="<%=Testes.isNull(pProcesso,"")%>">
                            <input name="lim" type="hidden" id="lim" value="<%=lim%>">
                            <input name="pag" type="hidden" id="pag" value="<%=request.getParameter("pag")%>"></td>
                      </tr>
                    </table>
                </form></td>
              </tr>
            </table></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    		<td height="15">
	    		<% 
				int codEscola = usuarioLogado.getCodEscola();
	    		if (codEscola == 2){%>
	    			<jsp:include page="include/rodapeCpg.jsp" flush="true" />
	    		
	    		<%} else if (codEscola ==3){%>
	    			<jsp:include page="include/rodapeCmv.jsp" flush="true" />
	    		<%} else {%>
	    			<jsp:include page="include/rodape.jsp" flush="true" />
	    		<%} %>
    		</td>
  </tr>
</table>
</body>
</html>